// 全局请求封装
const base_url = '/api'
// const base_url = 'http://10.194.152.195:8083/'

// 需要修改token，和根据实际修改请求头
export default (url, method, params) => {
	// 根据请求方法或URL来判断是否添加请求头

	// 获取本地token
	const token = uni.getStorageSync('token') || ''
	let header = {}
	header.token = token
	header['content-type'] = "application/json"

	return new Promise((resolve, reject) => {
		uni.request({
			url: base_url + url,
			method: method,
			header: header,
			data: params,
			success(response) {
				const res = response.data
				// console.log(res)
				// 根据返回的状态码做出对应的操作
				if (res.code === 113) {
					uni.showModal({
						title: '系统内部错误',
						content: '请联系管理员维护!',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					reject(res)
				} else if (res.code === undefined) {
					uni.showModal({
						showCancel: false,
						title: '登录信息已过期',
						content: '请重新登录!',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.reLaunch({
									url: '/pages/login/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					reject(res)
				} else {
					resolve(res.data)
				}
			},
			fail(err) {
				reject(err);
				console.log(err,'00000')
			},
			complete() {

			}
		});
	}).catch((e) => {});
}